package cs2340.droidceptiontodo.test;

import java.util.ArrayList;
import java.util.List;

import cs2340.droidceptiontodo.Database;
import cs2340.droidceptiontodo.ToDoItem;
import cs2340.droidceptiontodo.UserAccount;
import android.test.AndroidTestCase;
import android.test.RenamingDelegatingContext;

public class CheckUserTest extends AndroidTestCase {

	private Database database;
	private List<UserAccount> users;
	private List<ToDoItem> items;
	private static final String TEST_FILE_PREFIX = "test_";

	protected void setUp() throws Exception {
		super.setUp();
		
		RenamingDelegatingContext context = new RenamingDelegatingContext(getContext(), TEST_FILE_PREFIX);
		database = new Database(context);
		users = new ArrayList<UserAccount>();
		items = new ArrayList<ToDoItem>();
		

		users.add(new UserAccount("susmita", "susmita", "s@gmail.com", "susmita"));
		users.add(new UserAccount("roberta", "roberta", "r@gmail.com", "roberta"));
		users.add(new UserAccount("sheena", "sheena", "sh@gmail.com", "sheena"));
		users.add(new UserAccount("taylor", "taylor", "t@gmail.com", "taylor"));
		users.add(new UserAccount("bob", "taylor", "t@gmail.com", "taylor"));
		users.add(new UserAccount("sam", "susmita", "s@gmail.com", "susmita"));
		users.add(new UserAccount("sam", "sam", "s@gmail.com", "susmita"));
		
		 	items.add(new ToDoItem("0", "user", "details", "Work", "2015/04/05", "12:05", "location", true, null));
			items.add(new ToDoItem("1", "user", "details", "Work", "2014/04/05", "12:05", "location", false, null));
			items.add(new ToDoItem("2", "user", "details", "School", "2012/01/05", "12:05", "location", true, null));
			items.add(new ToDoItem("3", "user", "details", "School", "2012/12/05", "12:05", "location", false, null));
			items.add(new ToDoItem("4", "user", "details", "Personal", "2012/12/01", "12:05", "location", false, null));
			items.add(new ToDoItem("5", "user", "details", "Personal", "2011/04/05", "12:05", "location", true, null));
			database.open();
			for(ToDoItem item:items) {
				database.addItem(item);
			}
			for(UserAccount user: users){
				database.createUser(user.getID(),user.getPassword(), user.getEmail(), user.getName());
			}
	}
	
	public void testPreConditions() {
	    assertNotNull(database);
	}

	public void testSetSetting() {
		assertEquals(database.checkUser("susmita","susmita"), 1);
		assertEquals(database.checkUser("susmita", "bob"), 0);
		assertEquals(database.checkUser("erin", "sam"), -1);
		assertEquals(database.checkUser(null, null), -1);
		
	}
	
	@Override
	protected void tearDown() throws Exception {
	    super.tearDown();

	    database.close();
	    database = null;
	}
	
}
